package com.home.biz;/**
 * @author chenxf
 * @date 2022/4/19 16:39
 */

import com.github.pagehelper.PageHelper;
import com.home.base.biz.BaseBiz;
import com.home.entity.PolicyNewsInfo;
import com.home.entity.PolicySiteConfig;
import com.home.mapper.PolicyNewsInfoMapper;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

/**
 * @author chenxf
 * @date 2022/4/19 16:39
 */
@Service
public class PolicyNewsInfoBiz extends BaseBiz<PolicyNewsInfoMapper, PolicyNewsInfo> {

    public List<PolicyNewsInfo> list(int limit, int offset,  String orderStr) {
        Example example = new Example(PolicyNewsInfo.class);
        example.setOrderByClause("create_time " + orderStr);
        PageHelper.startPage(offset, limit);
        return selectByExample(example);
    }

    public PolicyNewsInfo fetchLastNews(Long siteId){
//        return selectById(140);

        Example example=new Example(PolicyNewsInfo.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("siteId",siteId);

        example.setOrderByClause(" create_time desc ,fetch_url desc limit 1");

        List<PolicyNewsInfo> list=selectByExample(example);
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
